package cn.net.xyan.easy.spring.jpa.support;

import cn.net.xyan.easy.spring.core.config.AutoConfigManagerFactory;
import cn.net.xyan.easy.spring.core.config.IAutoConfigManager;
import cn.net.xyan.easy.spring.core.utils.JsonHelper;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;

import java.lang.annotation.Annotation;
import java.util.Set;

/**
 * Created by xiashenpin on 16/1/16.
 */
public class EasyAnnotationRepositoryConfigureationSource extends AnnotationRepositoryConfigurationSource {

    @Override
    public Iterable<String> getBasePackages() {
        Set<String> ex = AutoConfigManagerFactory.autoConfigManager().readValue(IAutoConfigManager.RepositoryScanPackagesKey, JsonHelper.StringSet);
        Iterable<String> is =  super.getBasePackages();
        for (String s : is){
            ex.add(s);
        }
        return ex;
    }

    /**
     * Creates a new {@link AnnotationRepositoryConfigurationSource} from the given {@link AnnotationMetadata} and
     * annotation.
     *
     * @param metadata
     * @param annotation     must not be {@literal null}.
     * @param resourceLoader must not be {@literal null}.
     * @param environment
     */
    public EasyAnnotationRepositoryConfigureationSource(AnnotationMetadata metadata, Class<? extends Annotation> annotation, ResourceLoader resourceLoader, Environment environment) {
        super(metadata, annotation, resourceLoader, environment);
    }
}
